<template>
  <div>
    <Panel>
      <span slot="title">店铺管理</span>
      <div slot="btn">
        <el-button type="primary" @click="save">保存</el-button>
      </div>
      <div slot="main">
        <div class="sol">
          <el-form ref="form" :model="form" label-width="80px">
            <!-- 店铺名称 -->
            <el-form-item label="店铺名称">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
            <!-- 店铺公告 -->
            <el-form-item label="店铺公告">
              <el-input type="textarea" v-model="form.bulletin"></el-input>
            </el-form-item>
            <!-- 店铺头像 -->
            <el-form-item label="店铺头像">
              <el-upload
                class="avatar-uploader"
                action="http://sell.h5.itsource.cn:8087/shop/upload"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <img v-if="imageUrl" :src="img" class="avatar" />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
            <!-- 店铺图片 -->
            <el-form-item label="店铺图片">
              <el-upload
                action="http://sell.h5.itsource.cn:8087/shop/upload"
                list-type="picture-card"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog
                :visible.sync="dialogVisible"
                v-for="(v, i) in pics"
                :key="i"
              >
                <img width="100%" :src="v" alt="" />
              </el-dialog>
            </el-form-item>
            <!-- 配送费 -->
            <el-form-item label="配送费">
              <el-input v-model="form.deliveryPrice"></el-input>
            </el-form-item>
            <!-- 配送时间 -->
            <el-form-item label="配送时间">
              <el-input v-model="form.deliveryTime"></el-input>
            </el-form-item>
            <!-- 配送描述 -->
            <el-form-item label="配送描述">
              <el-input v-model="form.description"></el-input>
            </el-form-item>
            <!-- 店铺评分 -->
            <el-form-item label="店铺评分">
              <el-input v-model="form.score"></el-input>
            </el-form-item>
            <!-- 销量 -->
            <el-form-item label="销量">
              <el-input v-model="form.sellCount"></el-input>
            </el-form-item>
            <!-- 活动 -->
            <el-form-item label="活动">
              <el-checkbox v-model="checked">在线支付满28减5</el-checkbox>
              <el-checkbox v-model="checked">VC无限橙果汁全场8折</el-checkbox>
              <el-checkbox v-model="checked">单人精彩套餐</el-checkbox>
              <el-checkbox v-model="checked">特技饮品8折抢购</el-checkbox>
              <el-checkbox v-model="checked">单人特色套餐</el-checkbox>
            </el-form-item>
            <!-- 营业时间 -->
            <div class="time">
              营业时间
              <el-date-picker
                v-model="form.date"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
              <el-button type="primary" @click="onS">查询</el-button>
            </div>
          </el-form>
        </div>
      </div>
    </Panel>
  </div>
</template>

<script>
import Panel from "@/components/panel.vue";
import { infoApi, editApi } from "@/api/shop";
export default {
  data() {
    return {
      form: {},
      imageUrl: "",
      dialogImageUrl: "",
      dialogVisible: false,
      checked: "",
      img: "",
      pics: [],
      supports: [],
    };
  },
  components: {
    Panel,
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      infoApi().then((res) => {
       // console.log(res);
        this.form = res.data.data;
        this.img = res.data.data.avatar;
        this.pics = res.data.data.pics;
       // console.log(this.pics);
      });
    },
    handleAvatarSuccess(res, file) {
     // console.log(res);
      this.img = res.imgUrl;
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    onS() {},

    async save() {
    //  console.log(this.form);
      let res=await editApi(this.form);
    },

    handleRemove(file, fileList) {
     // console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
    //  console.log(file);

      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.sol {
  overflow-y: scroll;
  height: 750px;
}
::-webkit-scrollbar {
  width: 0;
}
/deep/.el-input__inner {
  width: 500px;
}
/deep/.el-textarea__inner {
  width: 500px;
}
</style>